package jnpf.service.impl;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jnpf.base.UserInfo;
import jnpf.config.PermissionsConfig;
import jnpf.entity.*;
import jnpf.mapper.ZXGL_XiangMuLiXiang_MingXiMapper;
import jnpf.model.zxgl_xiangmulixiang_mingxi.ZXGL_FileListVO;
import jnpf.model.zxgl_xiangmulixiang_mingxi.ZXGL_FilePagination;
import jnpf.model.zxgl_xiangmulixiang_mingxi.ZXGL_XiangMuLiXiang_MingXiPagination;
import jnpf.model.zxgl_xiangmulixiang_mingxi.ZXGL_XiangMuLiXiang_MingXiQuery;
import jnpf.service.*;
import jnpf.util.DateUtil;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import jnpf.utils.AIUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ZXGL_XiangMuLiXiang_MingXi
 * 版本： V2.0
 * 版权： 河北交投智能交通技术有限责任公司
 * 作者： 数字交投项目组
 * 日期： 2025-03-20
 */
@Service
public class ZXGL_XiangMuLiXiang_MingXiServiceImpl extends ServiceImpl<ZXGL_XiangMuLiXiang_MingXiMapper, ZXGL_XiangMuLiXiang_MingXiEntity> implements ZXGL_XiangMuLiXiang_MingXiService {

    private static final Logger logger = LoggerFactory.getLogger(AIUtil.class);

    @Autowired
    private UserProvider userProvider;

    @Autowired
    private ZXGL_XiangMuFenJie_mingxibiaoService zxglXiangMuFenJieMingxibiaoService;

    @Autowired
    private ZXGL_LiXiangGuanLiService zxgl_liXiangGuanLiService;


    @Autowired
    private ZXGL_XiangMuFanKuiService zxgl_xiangMuFanKuiService;

    @Autowired
    private ZXGL_RenWuFanKuiService zxgl_renWuFanKuiService;

    @Autowired
    private ZXGL_XiangMuJieXiangService zxgl_xiangMuJieXiangService;
    @Resource
    PermissionsConfig permissionsConfig;
    @Autowired
    private ObjectMapper objectMapper;


    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getList(ZXGL_XiangMuLiXiang_MingXiPagination zXGL_XiangMuLiXiang_MingXiPagination) {
        List<String> AllIdList = new ArrayList();
        int total = 0;
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> zXGL_XiangMuLiXiang_MingXiQueryWrapper = new QueryWrapper<>();
        //TODO 增加权限逻辑
        UserInfo userInfo = userProvider.get();
        if (!userInfo.getIsAdministrator()) {
            String alldataRoleId = permissionsConfig.getAlldataRoleid();
            List<String> roleIds = userInfo.getRoleIds();
            if (roleIds == null || (StringUtils.isNotBlank(alldataRoleId) && !roleIds.contains(alldataRoleId))) {
                //项目库：创建人看本人数据；创建人部门负责人看本部门数据；创建人部门主管领导看所管理部门数据；主责人看自己负责项目数据；
                // 主责部门负责人看本部门负责项目数据；主责部门主管领导看所管理部门负责数据；协作人看自己协作项目数据；
                // 协作部门负责人看本部门协作项目数据；协作部门主管领导看所管理部门协作项目数据；
                String userId = userInfo.getUserId();
                zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().and(wrapper -> wrapper
                        .eq(ZXGL_XiangMuLiXiang_MingXiEntity::getCreatorUserId, userId)//创建人
                        .or()
                        .eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDepartmentManager, userId)//创建人部门负责人看本部门数据
                        .or()
                        .eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDepartmentHeadleader, userId)//创建人部门主管领导看所管理部门数据
                        .or()
                        .eq(ZXGL_XiangMuLiXiang_MingXiEntity::getZzr, userId)//主责人看自己负责项目数据
                        .or()
                        .eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDepartmentManagerZzbm, userId)//主责部门负责人看本部门负责项目数据
                        .or()
                        .eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDepartmentHeadleaderZzbm, userId)//主责部门主管领导看所管理部门负责数据
                        .or()
                        .like(ZXGL_XiangMuLiXiang_MingXiEntity::getXzr, userId)//协作人看自己协作项目数据
                        .or()
                        .like(ZXGL_XiangMuLiXiang_MingXiEntity::getDepartmentManagerXzbm, userId)//协作部门负责人看本部门协作项目数据
                        .or()
                        .like(ZXGL_XiangMuLiXiang_MingXiEntity::getDepartmentHeadleaderXzbm, userId)//协作部门主管领导看所管理部门协作项目数据
                );
            }
        }
        int zXGL_XiangMuLiXiang_MingXiNum = 0;
        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmmc())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().like(ZXGL_XiangMuLiXiang_MingXiEntity::getXmmc, zXGL_XiangMuLiXiang_MingXiPagination.getXmmc());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmbh())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().like(ZXGL_XiangMuLiXiang_MingXiEntity::getXmbh, zXGL_XiangMuLiXiang_MingXiPagination.getXmbh());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmly())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getXmly, zXGL_XiangMuLiXiang_MingXiPagination.getXmly());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmlx())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getXmlx, zXGL_XiangMuLiXiang_MingXiPagination.getXmlx());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getJhkssj())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            List<String> JhkssjList = zXGL_XiangMuLiXiang_MingXiPagination.getJhkssj();
            Long fir = Long.valueOf(JhkssjList.get(0));
            Long sec = Long.valueOf(JhkssjList.get(1));

            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().ge(ZXGL_XiangMuLiXiang_MingXiEntity::getJhkssj, new Date(fir))
                    .le(ZXGL_XiangMuLiXiang_MingXiEntity::getJhkssj, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getJhjssj())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            List<String> JhjssjList = zXGL_XiangMuLiXiang_MingXiPagination.getJhjssj();
            Long fir = Long.valueOf(JhjssjList.get(0));
            Long sec = Long.valueOf(JhjssjList.get(1));

            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().ge(ZXGL_XiangMuLiXiang_MingXiEntity::getJhjssj, new Date(fir))
                    .le(ZXGL_XiangMuLiXiang_MingXiEntity::getJhjssj, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getZzbm())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().in(ZXGL_XiangMuLiXiang_MingXiEntity::getZzbm, zXGL_XiangMuLiXiang_MingXiPagination.getZzbm());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getZzr())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getZzr, zXGL_XiangMuLiXiang_MingXiPagination.getZzr());
        }

        if (AllIdList.size() > 0) {
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().in(ZXGL_XiangMuLiXiang_MingXiEntity::getId, AllIdList);
        }
        //排序
//        if (StringUtil.isEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getSidx())) {
//            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().orderByDesc(ZXGL_XiangMuLiXiang_MingXiEntity::getJhkssj);
//        } else {
//            try {
//                String sidx = zXGL_XiangMuLiXiang_MingXiPagination.getSidx();
//                ZXGL_XiangMuLiXiang_MingXiEntity zXGL_XiangMuLiXiang_MingXiEntity = new ZXGL_XiangMuLiXiang_MingXiEntity();
//                Field declaredField = zXGL_XiangMuLiXiang_MingXiEntity.getClass().getDeclaredField(sidx);
//                declaredField.setAccessible(true);
//                String value = declaredField.getAnnotation(TableField.class).value();
//                zXGL_XiangMuLiXiang_MingXiQueryWrapper = "asc".equals(zXGL_XiangMuLiXiang_MingXiPagination.getSort().toLowerCase()) ? zXGL_XiangMuLiXiang_MingXiQueryWrapper.orderByAsc(value) : zXGL_XiangMuLiXiang_MingXiQueryWrapper.orderByDesc(value);
//            } catch (NoSuchFieldException e) {
//                e.printStackTrace();
//            }
//        }
        zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getJszt, "669883054189213317");
        zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().orderByDesc(ZXGL_XiangMuLiXiang_MingXiEntity::getCreatorTime);
        if ((total > 0 && AllIdList.size() > 0) || total == 0) {
            Page<ZXGL_XiangMuLiXiang_MingXiEntity> page = new Page<>(zXGL_XiangMuLiXiang_MingXiPagination.getCurrentPage(), zXGL_XiangMuLiXiang_MingXiPagination.getPageSize());
            IPage<ZXGL_XiangMuLiXiang_MingXiEntity> userIPage = this.page(page, zXGL_XiangMuLiXiang_MingXiQueryWrapper);
            return zXGL_XiangMuLiXiang_MingXiPagination.setData(userIPage.getRecords(), userIPage.getTotal());
        } else {
            List<ZXGL_XiangMuLiXiang_MingXiEntity> list = new ArrayList();
            return zXGL_XiangMuLiXiang_MingXiPagination.setData(list, list.size());
        }
    }

    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getTypeList(ZXGL_XiangMuLiXiang_MingXiPagination zXGL_XiangMuLiXiang_MingXiPagination, String dataType) {
        String userId = userProvider.get().getUserId();
        List<String> AllIdList = new ArrayList();
        int total = 0;
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> zXGL_XiangMuLiXiang_MingXiQueryWrapper = new QueryWrapper<>();
        int zXGL_XiangMuLiXiang_MingXiNum = 0;
        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmmc())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().like(ZXGL_XiangMuLiXiang_MingXiEntity::getXmmc, zXGL_XiangMuLiXiang_MingXiPagination.getXmmc());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmbh())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().like(ZXGL_XiangMuLiXiang_MingXiEntity::getXmbh, zXGL_XiangMuLiXiang_MingXiPagination.getXmbh());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmly())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getXmly, zXGL_XiangMuLiXiang_MingXiPagination.getXmly());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmlx())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getXmlx, zXGL_XiangMuLiXiang_MingXiPagination.getXmlx());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getJhkssj())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            List<String> JhkssjList = zXGL_XiangMuLiXiang_MingXiPagination.getJhkssj();
            Long fir = Long.valueOf(JhkssjList.get(0));
            Long sec = Long.valueOf(JhkssjList.get(1));

            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().ge(ZXGL_XiangMuLiXiang_MingXiEntity::getJhkssj, new Date(fir))
                    .le(ZXGL_XiangMuLiXiang_MingXiEntity::getJhkssj, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getJhjssj())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            List<String> JhjssjList = zXGL_XiangMuLiXiang_MingXiPagination.getJhjssj();
            Long fir = Long.valueOf(JhjssjList.get(0));
            Long sec = Long.valueOf(JhjssjList.get(1));

            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().ge(ZXGL_XiangMuLiXiang_MingXiEntity::getJhjssj, new Date(fir))
                    .le(ZXGL_XiangMuLiXiang_MingXiEntity::getJhjssj, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getZzbm())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getZzbm, zXGL_XiangMuLiXiang_MingXiPagination.getZzbm());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getZzr())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getZzr, zXGL_XiangMuLiXiang_MingXiPagination.getZzr());
        }

        if (AllIdList.size() > 0) {
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().in(ZXGL_XiangMuLiXiang_MingXiEntity::getId, AllIdList);
        }
        //排序
        if (StringUtil.isEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getSidx())) {
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().orderByDesc(ZXGL_XiangMuLiXiang_MingXiEntity::getXmbh);
        } else {
            try {
                String sidx = zXGL_XiangMuLiXiang_MingXiPagination.getSidx();
                ZXGL_XiangMuLiXiang_MingXiEntity zXGL_XiangMuLiXiang_MingXiEntity = new ZXGL_XiangMuLiXiang_MingXiEntity();
                Field declaredField = zXGL_XiangMuLiXiang_MingXiEntity.getClass().getDeclaredField(sidx);
                declaredField.setAccessible(true);
                String value = declaredField.getAnnotation(TableField.class).value();
                zXGL_XiangMuLiXiang_MingXiQueryWrapper = "asc".equals(zXGL_XiangMuLiXiang_MingXiPagination.getSort().toLowerCase()) ? zXGL_XiangMuLiXiang_MingXiQueryWrapper.orderByAsc(value) : zXGL_XiangMuLiXiang_MingXiQueryWrapper.orderByDesc(value);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
        }
        if ("0".equals(dataType)) {
            if ((total > 0 && AllIdList.size() > 0) || total == 0) {
                Page<ZXGL_XiangMuLiXiang_MingXiEntity> page = new Page<>(zXGL_XiangMuLiXiang_MingXiPagination.getCurrentPage(), zXGL_XiangMuLiXiang_MingXiPagination.getPageSize());
                IPage<ZXGL_XiangMuLiXiang_MingXiEntity> userIPage = this.page(page, zXGL_XiangMuLiXiang_MingXiQueryWrapper);
                return zXGL_XiangMuLiXiang_MingXiPagination.setData(userIPage.getRecords(), userIPage.getTotal());
            } else {
                List<ZXGL_XiangMuLiXiang_MingXiEntity> list = new ArrayList();
                return zXGL_XiangMuLiXiang_MingXiPagination.setData(list, list.size());
            }
        } else {
            return this.list(zXGL_XiangMuLiXiang_MingXiQueryWrapper);
        }
    }

    @Override
    public ZXGL_XiangMuLiXiang_MingXiEntity getInfo(String id) {
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getId, id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(ZXGL_XiangMuLiXiang_MingXiEntity entity) {
        this.save(entity);
    }

    @Override
    public boolean update(String id, ZXGL_XiangMuLiXiang_MingXiEntity entity) {
        entity.setId(id);
        return this.updateById(entity);
    }

    @Override
    public void delete(ZXGL_XiangMuLiXiang_MingXiEntity entity) {
        if (entity != null) {
            this.removeById(entity.getId());
        }
    }
    //子表方法

    //列表子表数据方法


    @Override
    public ZXGL_XiangMuFenJie_ZhuBiaoEntity getXmliXiangById(String Id) {
        ZXGL_XiangMuLiXiang_MingXiEntity mingXiEntity = baseMapper.selectById(Id);
        if (mingXiEntity != null) {
            ZXGL_LiXiangGuanLiEntity guanLiEntity = zxgl_liXiangGuanLiService.getInfo(mingXiEntity.getMainid());
            if (guanLiEntity != null) {
                ZXGL_XiangMuFenJie_ZhuBiaoEntity entity = new ZXGL_XiangMuFenJie_ZhuBiaoEntity();
                // entity.setId(mingXiEntity.getId());
                entity.setXmmc(mingXiEntity.getXmmc());
                entity.setXmbh(mingXiEntity.getXmbh());
                entity.setJhksrq(mingXiEntity.getJhkssj());
                entity.setJhwcrq(mingXiEntity.getJhjssj());
                entity.setXmlx(mingXiEntity.getXmlx());
                entity.setXmly(mingXiEntity.getXmly());
                // entity.setSjlx(mingXiEntity.getSjlx());
                entity.setZdxm(mingXiEntity.getZdxm());
                entity.setXmfkzq(mingXiEntity.getFkzq());
                entity.setScwj(mingXiEntity.getXmwj());
                entity.setZrr(mingXiEntity.getZzr());
                entity.setSjlx(mingXiEntity.getMblx());
                entity.setGzmb(mingXiEntity.getGzmb());
                entity.setScwj(guanLiEntity.getScfj());
                if (mingXiEntity.getMbz() != null) {
                    entity.setSjz(mingXiEntity.getMbz().toString());
                }
                entity.setZrbm(mingXiEntity.getZzbm());
                entity.setMbzdw(mingXiEntity.getMbzdw());
                return entity;
            }
        }
        return null;
    }

    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getTodayList() {
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> zXGL_XiangMuLiXiang_MingXiQueryWrapper = new QueryWrapper<>();
        zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().le(ZXGL_XiangMuLiXiang_MingXiEntity::getJhkssj, LocalDate.now());
        zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getZt, "667276252607944005")
                .or().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getZt, "")
                .or().isNull(ZXGL_XiangMuLiXiang_MingXiEntity::getZt);
        return baseMapper.selectList(zXGL_XiangMuLiXiang_MingXiQueryWrapper);
    }

    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getList(ZXGL_XiangMuLiXiang_MingXiQuery zXGL_XiangMuLiXiang_MingXiQuery) {
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> zXGL_XiangMuLiXiang_MingXiQueryWrapper = new QueryWrapper<>();
        if (!StringUtil.isEmpty(zXGL_XiangMuLiXiang_MingXiQuery.getXmmc())) {
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().like(ZXGL_XiangMuLiXiang_MingXiEntity::getXmmc, zXGL_XiangMuLiXiang_MingXiQuery.getXmmc());
        }
        return baseMapper.selectList(zXGL_XiangMuLiXiang_MingXiQueryWrapper);
    }

    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getListTree(ZXGL_XiangMuLiXiang_MingXiPagination zXGL_XiangMuLiXiang_MingXiPagination) {
        List<String> listTree = zxglXiangMuFenJieMingxibiaoService.getListTree();

        String userId = userProvider.get().getUserId();
        List<String> AllIdList = new ArrayList();
        int total = 0;
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> zXGL_XiangMuLiXiang_MingXiQueryWrapper = new QueryWrapper<>();
        if (listTree != null && listTree.size() > 0) {
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().in(ZXGL_XiangMuLiXiang_MingXiEntity::getId, listTree);
        }
        int zXGL_XiangMuLiXiang_MingXiNum = 0;
        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmmc())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().like(ZXGL_XiangMuLiXiang_MingXiEntity::getXmmc, zXGL_XiangMuLiXiang_MingXiPagination.getXmmc());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmbh())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().like(ZXGL_XiangMuLiXiang_MingXiEntity::getXmbh, zXGL_XiangMuLiXiang_MingXiPagination.getXmbh());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmly())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getXmly, zXGL_XiangMuLiXiang_MingXiPagination.getXmly());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getXmlx())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getXmlx, zXGL_XiangMuLiXiang_MingXiPagination.getXmlx());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getJhkssj())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            List<String> JhkssjList = zXGL_XiangMuLiXiang_MingXiPagination.getJhkssj();
            Long fir = Long.valueOf(JhkssjList.get(0));
            Long sec = Long.valueOf(JhkssjList.get(1));

            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().ge(ZXGL_XiangMuLiXiang_MingXiEntity::getJhkssj, new Date(fir))
                    .le(ZXGL_XiangMuLiXiang_MingXiEntity::getJhkssj, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getJhjssj())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            List<String> JhjssjList = zXGL_XiangMuLiXiang_MingXiPagination.getJhjssj();
            Long fir = Long.valueOf(JhjssjList.get(0));
            Long sec = Long.valueOf(JhjssjList.get(1));

            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().ge(ZXGL_XiangMuLiXiang_MingXiEntity::getJhjssj, new Date(fir))
                    .le(ZXGL_XiangMuLiXiang_MingXiEntity::getJhjssj, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getZzbm())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getZzbm, zXGL_XiangMuLiXiang_MingXiPagination.getZzbm());
        }

        if (StringUtil.isNotEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getZzr())) {
            zXGL_XiangMuLiXiang_MingXiNum++;
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getZzr, zXGL_XiangMuLiXiang_MingXiPagination.getZzr());
        }

        if (AllIdList.size() > 0) {
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().in(ZXGL_XiangMuLiXiang_MingXiEntity::getId, AllIdList);
        }
        //排序
        if (StringUtil.isEmpty(zXGL_XiangMuLiXiang_MingXiPagination.getSidx())) {
            zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().orderByDesc(ZXGL_XiangMuLiXiang_MingXiEntity::getXmbh);
        } else {
            try {
                String sidx = zXGL_XiangMuLiXiang_MingXiPagination.getSidx();
                ZXGL_XiangMuLiXiang_MingXiEntity zXGL_XiangMuLiXiang_MingXiEntity = new ZXGL_XiangMuLiXiang_MingXiEntity();
                Field declaredField = zXGL_XiangMuLiXiang_MingXiEntity.getClass().getDeclaredField(sidx);
                declaredField.setAccessible(true);
                String value = declaredField.getAnnotation(TableField.class).value();
                zXGL_XiangMuLiXiang_MingXiQueryWrapper = "asc".equals(zXGL_XiangMuLiXiang_MingXiPagination.getSort().toLowerCase()) ? zXGL_XiangMuLiXiang_MingXiQueryWrapper.orderByAsc(value) : zXGL_XiangMuLiXiang_MingXiQueryWrapper.orderByDesc(value);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
        }
        if ((total > 0 && AllIdList.size() > 0) || total == 0) {
            Page<ZXGL_XiangMuLiXiang_MingXiEntity> page = new Page<>(zXGL_XiangMuLiXiang_MingXiPagination.getCurrentPage(), zXGL_XiangMuLiXiang_MingXiPagination.getPageSize());
            IPage<ZXGL_XiangMuLiXiang_MingXiEntity> userIPage = this.page(page, zXGL_XiangMuLiXiang_MingXiQueryWrapper);
            return zXGL_XiangMuLiXiang_MingXiPagination.setData(userIPage.getRecords(), userIPage.getTotal());
        } else {
            List<ZXGL_XiangMuLiXiang_MingXiEntity> list = new ArrayList();
            return zXGL_XiangMuLiXiang_MingXiPagination.setData(list, list.size());
        }
    }

    /**
     * 日周期
     *
     * @return
     */
    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getFankuiByDate() {
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDskg, "1");
        queryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getFkpl, "1");
        // LambdaQueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> eq = wrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDskg, "1").eq(ZXGL_XiangMuLiXiang_MingXiEntity::getFkpl, "1");
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 周反馈
     *
     * @return
     */
    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getFankuiByWeek() {
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDskg, "1");
        queryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getFkpl, "2");
        // LambdaQueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> eq = wrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDskg, "1").eq(ZXGL_XiangMuLiXiang_MingXiEntity::getFkpl, "2");
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 月反馈
     *
     * @return
     */
    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getFankuiByMonth() {
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDskg, "1");
        queryWrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getFkpl, "3");
        // LambdaQueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> eq = wrapper.lambda().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getDskg, "1").eq(ZXGL_XiangMuLiXiang_MingXiEntity::getFkpl, "3");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getUnfinishedBefore5Day() {
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> zXGL_XiangMuLiXiang_MingXiQueryWrapper = new QueryWrapper<>();
        LocalDate date = LocalDate.now();
        date = date.plusDays(5);
        zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().le(ZXGL_XiangMuLiXiang_MingXiEntity::getJhjssj, date);
        zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().ne(ZXGL_XiangMuLiXiang_MingXiEntity::getXmjd, "100")
                .or().isNull(ZXGL_XiangMuLiXiang_MingXiEntity::getXmjd)
                .or().eq(ZXGL_XiangMuLiXiang_MingXiEntity::getXmjd, "");
        return baseMapper.selectList(zXGL_XiangMuLiXiang_MingXiQueryWrapper);
    }

    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> selectAll(String xmmc, String userId) {
        UserInfo userInfo = userProvider.get();
        if (!userInfo.getIsAdministrator()) {
            String alldataRoleId = permissionsConfig.getAlldataRoleid();
            List<String> roleIds = userInfo.getRoleIds();
            if (roleIds == null || (StringUtils.isNotBlank(alldataRoleId) && !roleIds.contains(alldataRoleId))) {
                return baseMapper.selectAll(xmmc, userId);
            }
        }
        return baseMapper.selectAll(xmmc, "");
    }

    @Override
    public List<ZXGL_FileListVO> getList(ZXGL_FilePagination zxglFilePagination) {
        List<ZXGL_FileListVO> list = new ArrayList<>();

        QueryWrapper<ZXGL_XiangMuFanKuiEntity> fkQueryWrapper = new QueryWrapper<>();
        fkQueryWrapper.lambda().eq(ZXGL_XiangMuFanKuiEntity::getXmid, zxglFilePagination.getXmid());
        List<ZXGL_XiangMuFanKuiEntity> xmList = zxgl_xiangMuFanKuiService.list(fkQueryWrapper);
        //项目反馈交付物
        if (xmList != null && xmList.size() > 0) {
            try {
                for (ZXGL_XiangMuFanKuiEntity entity : xmList) {
                    // logger.info("entity.getScwj():============>" + entity.getScwj());
                    if (StringUtil.isNotEmpty(entity.getScwj()) && entity.getScwj().length() > 4) {
                        JsonNode nodes = objectMapper.readTree(entity.getScwj());
                        // 遍历JsonArray
                        for (JsonNode node : nodes) {
                            ZXGL_FileListVO model = new ZXGL_FileListVO();
                            model.setCreateUserName(entity.getCreatorUser());
                            model.setCreateTime(String.valueOf(entity.getCreatorTime()));
                            model.setName(node.get("name").asText());
                            model.setFileId(node.get("fileId").asText());
                            model.setUrl(node.get("url").asText());
                            model.setFileVersionId(node.get("fileVersionId").asText());
                            list.add(model);
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        //项目协办人反馈交付物
        List<ZXGL_XieBanXiangMuFanKuiMXEntity> xmxbrfkList = zxgl_xiangMuFanKuiService.GetZXGL_XieBanXiangMuFanKuiMXListByXmId(zxglFilePagination.getXmid());
        if (xmxbrfkList != null && xmxbrfkList.size() > 0) {
            try {
                for (ZXGL_XieBanXiangMuFanKuiMXEntity entity : xmxbrfkList) {
                    if (StringUtil.isNotEmpty(entity.getJfw()) && entity.getJfw().length() > 4) {

                        JsonNode nodes = objectMapper.readTree(entity.getJfw());
                        // 遍历JsonArray
                        for (JsonNode node : nodes) {
                            ZXGL_FileListVO model = new ZXGL_FileListVO();
                            model.setCreateUserName(entity.getCreatorUser());
                            model.setCreateTime(String.valueOf(entity.getCreatorTime()));
                            model.setName(node.get("name").asText());
                            model.setFileId(node.get("fileId").asText());
                            model.setUrl(node.get("url").asText());
                            model.setFileVersionId(node.get("fileVersionId").asText());
                            list.add(model);
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        //任务反馈交付物
        QueryWrapper<ZXGL_RenWuFanKuiEntity> rwqQueryWrapper = new QueryWrapper<>();
        rwqQueryWrapper.lambda().eq(ZXGL_RenWuFanKuiEntity::getXmid, zxglFilePagination.getXmid());
        List<ZXGL_RenWuFanKuiEntity> rwList = zxgl_renWuFanKuiService.list(rwqQueryWrapper);
        if (rwList != null && rwList.size() > 0) {
            try {
                for (ZXGL_RenWuFanKuiEntity entity : rwList) {
                    String mainid = entity.getId();
                    // logger.info("entity.getScfj():============>" + entity.getScfj());
                    if (StringUtil.isNotEmpty(entity.getScfj()) && entity.getScfj().length() > 4) {
                        JsonNode nodes = objectMapper.readTree(entity.getScfj());
                        // 遍历JsonArray
                        for (JsonNode node : nodes) {
                            ZXGL_FileListVO model = new ZXGL_FileListVO();
                            model.setCreateUserName(entity.getCreatorUser());
                            model.setCreateTime(String.valueOf(entity.getCreatorTime()));
                            model.setName(node.get("name").asText());
                            model.setFileId(node.get("fileId").asText());
                            model.setUrl(node.get("url").asText());
                            model.setFileVersionId(node.get("fileVersionId").asText());
                            list.add(model);
                        }
                    }
                    //继续获取协办人反馈的
                    List<ZXGL_XieBanRenWuFanKuiMXEntity> zxglXieBanRenWuFanKuiMXEntities = zxgl_renWuFanKuiService.GetZXGL_XieBanRenWuFanKuiMXList(mainid);
                    for (ZXGL_XieBanRenWuFanKuiMXEntity entity1 : zxglXieBanRenWuFanKuiMXEntities) {
                        if (StringUtil.isNotEmpty(entity1.getJfw()) && entity1.getJfw().length() > 4) {
                            JsonNode nodes = objectMapper.readTree(entity1.getJfw());
                            // 遍历JsonArray
                            for (JsonNode node : nodes) {
                                ZXGL_FileListVO model = new ZXGL_FileListVO();
                                model.setCreateUserName(entity1.getCreatorUser());
                                model.setCreateTime(String.valueOf(entity1.getCreatorTime()));
                                model.setName(node.get("name").asText());
                                model.setFileId(node.get("fileId").asText());
                                model.setUrl(node.get("url").asText());
                                model.setFileVersionId(node.get("fileVersionId").asText());
                                list.add(model);
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        //项目结项交付物
        QueryWrapper<ZXGL_XiangMuJieXiangEntity> jxQueryWrapper = new QueryWrapper<>();
        jxQueryWrapper.lambda().eq(ZXGL_XiangMuJieXiangEntity::getXmid, zxglFilePagination.getXmid());
        List<ZXGL_XiangMuJieXiangEntity> jxList = zxgl_xiangMuJieXiangService.list(jxQueryWrapper);
        logger.info("jxList:============>" + jxList);
        if (jxList != null && jxList.size() > 0) {
            try {
                for (ZXGL_XiangMuJieXiangEntity entity : jxList) {
                    // logger.info("entity.getJxwj():============>" + entity.getJxwj());
                    if (StringUtil.isNotEmpty(entity.getJxwj()) && entity.getJxwj().length() > 4) {
                        JsonNode nodes = objectMapper.readTree(entity.getJxwj());
                        // 遍历JsonArray
                        for (JsonNode node : nodes) {
                            ZXGL_FileListVO model = new ZXGL_FileListVO();
                            model.setCreateUserName(entity.getCreatorUser());
                            model.setCreateTime(String.valueOf(entity.getCreatorTime()));
                            model.setName(node.get("name").asText());
                            model.setFileId(node.get("fileId").asText());
                            model.setUrl(node.get("url").asText());
                            model.setFileVersionId(node.get("fileVersionId").asText());
                            list.add(model);
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }


        long skipNum = (zxglFilePagination.getCurrentPage() - 1) * zxglFilePagination.getPageSize();
        if (StringUtil.isNotEmpty(zxglFilePagination.getName())) {
            return list.stream().filter(o -> o.getName().contains(zxglFilePagination.getName()))
                    .skip(skipNum)
                    .limit(zxglFilePagination.getPageSize())
                    .collect(Collectors.toList());
        }

        logger.info("list:============>" + list);
        logger.info("zxglFilePagination:============>" + zxglFilePagination);

        return list.stream()
                .skip(skipNum)
                .limit(zxglFilePagination.getPageSize())
                .collect(Collectors.toList());

    }

    @Override
    public List<ZXGL_XiangMuLiXiang_MingXiEntity> getOverdueList(List<String> yjbjs) {
        QueryWrapper<ZXGL_XiangMuLiXiang_MingXiEntity> zXGL_XiangMuLiXiang_MingXiQueryWrapper = new QueryWrapper<>();
        zXGL_XiangMuLiXiang_MingXiQueryWrapper.lambda().in(ZXGL_XiangMuLiXiang_MingXiEntity::getYjbj, yjbjs);
        return baseMapper.selectList(zXGL_XiangMuLiXiang_MingXiQueryWrapper);
    }


}